package com.cms.jy;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestJy {
    public static void main(String[] args) throws Exception {
        GenMusicByApi genMusicByApi = new GenMusicByApi();
        // 创建草稿
        String draftId = genMusicByApi.createDraftAndGetId();
        System.out.println(draftId);
        draftId = genMusicByApi.addText("演唱：", genMusicByApi.parseFrameTime("00:00:01:18"), genMusicByApi.parseFrameTime("00:00:08:29"),
                draftId, genMusicByApi.calculateCoverY(366), genMusicByApi.calculateCoverX(-342),
                "圆体", "#FFFFFF", 15.0, "test_44", null, null, null, null, null, null, null,
                null, null, null, "开幕", 1.6, "扭曲模糊", 1.2, 1920, 1080, null,
                null, null,  null, null, null, true, 0.00, -45.00, "#00000",
                8, 0.33, 0.36, 0.36);
        // 开头 云烟效果视频
//        String start1VideoUrl = jyUtils.RES_TPL_URL + "/FW-6EBW--MLV0-389L-BWRL-KVFBKHRQJBBZ.mp4";
//        double startTime1 = jyUtils.parseFrameTime("00:00:00:06");
//        double vstartDuration1 = jyUtils.parseFrameTime("00:00:01:18") -startTime1 ;
//        draftId = jyUtils.addVideo(start1VideoUrl, 0.0, 0.0,
//                1920, 1080, draftId, jyUtils.calculateCoverY(665), jyUtils.calculateCoverX(-219),
//                1.59, 1.59, 3.6/vstartDuration1, startTime1, "test_55", null, vstartDuration1, "模糊",
//                0.7, 0.0, null,
//                null, null, null, null, null, false, null,
//                null, null, 1.0, "screen",null, 90.0);

        String finalDraftId = draftId;
        String result = genMusicByApi.saveDraft(finalDraftId, null);
        log.info("草稿保存成功，URL: {}", result);

        int progress = 0;
        do {
            JSONObject status = null;
            try {
                status = genMusicByApi.queryDraftStatus(draftId);
                progress =  status.getIntValue("progress");
                log.info("进度：{}%，{}/{}", status.getString("progress"), status.getIntValue("completed_files"), status.getIntValue("total_files"));
            } catch (Exception e) {
                log.error("查询进度失败:{}", e.getMessage());
            }
        } while (progress!=100);
    }
}
